package hust.rpc.handler;

import hust.rpc.constants.Constants;
import hust.rpc.enums.RpcResponseType;
import hust.rpc.pojo.Message;
import hust.rpc.pojo.RpcRequest;
import hust.rpc.pojo.RpcResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class TestHandler extends SimpleChannelInboundHandler<Message> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        List<Map<String, String>> services = Collections.singletonList(Collections.singletonMap("SOBXiong", "Test"));
        RpcRequest request = RpcRequest.builder()
                .args(new Object[]{services})
                .signature("hust.rpc.service.ProviderService.register(java.util.List)")
                .id(0L)
                .build();
        Message message = Message.builder()
                .codec(Constants.CODEC_KRYO)
                .version(Constants.VERSION)
                .messageType(Constants.REQUEST_TYPE)
                .data(request)
                .build();
        ctx.writeAndFlush(message);
        super.channelActive(ctx);
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {

    }
}
